package com.toprs.base.config

import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class InterceptorConfig(val jwtInterceptor: JwtInterceptor) : WebMvcConfigurer {

    override fun addInterceptors(registry: InterceptorRegistry) {
        val excludePaths: List<String> = mutableListOf(
            "/doc.html",
            "/webjars/**",
            "/swagger-resources/**",
            "/api/**",
            "/v3/api-docs/**",
            "/error",
            "/user/login", "/favicon.ico",  "/images/*",
        )
        registry.addInterceptor(jwtInterceptor).excludePathPatterns(excludePaths)
    }

    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        registry.addResourceHandler("doc.html")
            .addResourceLocations("classpath:/META-INF/resources/")
        registry.addResourceHandler("/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/")
    }


}